﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace QLNS.aspFrm
{
    public partial class frmDanhSachTienLuongCBCC : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            System.Data.DataTable table = MakeTable();
            var dscanbo = context.GetDanhSachTienLuongCBCB();
            foreach (var i in dscanbo)
            {
                System.Data.DataRow row;
                row = table.NewRow();
                row["HoTen"] = i.HoTen;
                if (i.GioiTinh == "Nam")
                {
                    row["GioiTinhNam"] = String.Format("{0:d/M/yyyy}",i.NgaySinh);
                }
                else if (i.GioiTinh == "Nữ")
                {
                    row["GioiTinhNu"] = String.Format("{0:d/M/yyyy}",i.NgaySinh);
                }
                row["ChucVuHienTai"] = i.ChucVuHienTai;
                row["ThoiGianGiuNgach"] = i.ThoiGianGiuNgach;
                row["MaNgachCC"] = i.MaNgachCC;
                var HeSoLuong=((i.BacLuong-1)* i.HeSoTang)+i.HeSoGoc;
                row["HeSoLuong"] = HeSoLuong;
                row["IDDonVi"] = i.IDDonVi;
                row["DonViCongTac"] = i.DonViCongTac;
                if (i.PhuCapChucVu != 0)
                {
                    row["HeSoPhuCapChucVu"] = i.PhuCapChucVu;
                }

                if (i.PhuCapTrachNhiem != 0)
                {
                    row["HeSoPhuCapTrachNhiem"] = i.PhuCapTrachNhiem;
                }

                if (i.PhuCapVuotKhung != 0)
                {
                    row["HeSoPhuCapVuotKhung"] = i.PhuCapVuotKhung;
                }

                if (i.PhuCapKhuVuc != 0)
                {
                    row["HeSoPhuCapKhuVuc"] = i.PhuCapKhuVuc;
                }

                if (i.PhuCapKhac != 0)
                {
                    row["HeSoPhuCapKhac"] = i.PhuCapKhac;
                }

                row["TenPhongBan"] = i.TenPhongBan;
                row["IDPhongBan"] = i.ID;
                row["STT"] = i.STT;
                table.Rows.Add(row);

            }
            CrystalDecisions.CrystalReports.Engine.ReportDocument rd = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
            string strRptPath = Server.MapPath("~/") + "Reports//Report_DanhSachTienLuongCBCC.rpt";
            //Loading Report
            rd.Load(strRptPath);

            // Setting report data source
            if (table != null)
                rd.SetDataSource(table);
            CrystalReportViewer1.ReportSource = rd;
        }

        private System.Data.DataTable MakeTable()
        {
            System.Data.DataTable table = new System.Data.DataTable("Table");
            System.Data.DataColumn column;

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "HoTen";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.DateTime");
            column.ColumnName = "NgaySinh";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "GioiTinhNam";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "GioiTinhNu";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "ChucVuHienTai";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "ThoiGianGiuNgach";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "MaNgachCC";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.Double");
            column.ColumnName = "HeSoLuong";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.Int32");
            column.ColumnName = "IDDonVi";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "DonViCongTac";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.Double");
            column.ColumnName = "HeSoPhuCapChucVu";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.Double");
            column.ColumnName = "HeSoPhuCapTrachNhiem";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.Double");
            column.ColumnName = "HeSoPhuCapVuotKhung";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.Double");
            column.ColumnName = "HeSoPhuCapKhuVuc";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.Double");
            column.ColumnName = "HeSoPhuCapKhac";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.String");
            column.ColumnName = "TenPhongBan";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.Int32");
            column.ColumnName = "IDPhongBan";
            table.Columns.Add(column);

            column = new System.Data.DataColumn();
            column.DataType = System.Type.GetType("System.Int32");
            column.ColumnName = "STT";
            table.Columns.Add(column);

            return table;
        }
    }
}